import { _decorator, Component , Node, Label, Tween, game, director, Director } from "cc";

const {ccclass, property,menu} = _decorator;

@ccclass
@menu("use/全局消息")
export default class GlobalMessage extends Component {

    @property(Node)
    private labelSpr: Node = null;
    @property(Label)
    private label: Label = null;

    //private tween:Tween = null;

    static Inst:GlobalMessage = null

    //--------------------------

    currChapter_num:number = 1;
    currLevel_num:number = 1;

    //--------------------------
    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        GlobalMessage.Inst = this;
    }

    start () {
        game.addPersistRootNode(this.node);
        //this.node.zIndex = cc.macro.MAX_ZINDEX;

        //this.showGameMessage("666");
    }

    /**展示消息 */
    showGameMessage(messageStr:string){
        this.label.string = messageStr;

        //渲染之后执行
        // director.once(Director.EVENT_AFTER_DRAW, ()=>{
        //     this.labelSpr.width = this.label.node.width + 60;
        //     this.labelSpr.height = this.label.node.height + 30;
        // });

        // this.labelSpr.opacity = 255;
        // if(this.tween)this.tween.stop();
        // this.tween = tween(this.labelSpr).delay(0.3).to(1,{opacity:0});
        //this.tween.start();
    }

    // update (dt) {}
}
